package com.sailing.xjpb.web.base.advice.config;

import com.sailing.xjpb.common.web.translate.impl.DelegateTranslateHandler;
import com.sailing.xjpb.web.base.advice.SailingExceptionHandler;
import com.sailing.xjpb.web.base.advice.SailingResponseAdvisor;
import com.sailing.xjpb.web.base.advice.TranslateResponseAdvisor;
import com.sailing.xjpb.web.base.health.HealthCheck;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * web advisor返回值包装配置
 *
 * @author YW
 */
@Configuration
@EnableConfigurationProperties(value = ResponseAdvisorConfigProperties.class)
public class ControllerAdvisorAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(SailingResponseAdvisor.class)
    public SailingResponseAdvisor sailingResponseAdvisor() {
        return new SailingResponseAdvisor();
    }

    @Bean
    @ConditionalOnMissingBean(SailingExceptionHandler.class)
    public SailingExceptionHandler sailingExceptionHandler() {
        return new SailingExceptionHandler();
    }


    @Bean
    @ConditionalOnMissingBean(TranslateResponseAdvisor.class)
    public TranslateResponseAdvisor translateResponseAdvisor() {
        return new TranslateResponseAdvisor();
    }

    @Bean
    @ConditionalOnMissingBean(DelegateTranslateHandler.class)
    public DelegateTranslateHandler delegateTranslateHandler() {
        return new DelegateTranslateHandler();
    }

    @Bean
    @ConditionalOnMissingBean(HealthCheck.class)
    public HealthCheck healthCheck() {
        return new HealthCheck();
    }
}